import request from '@/utils/request'

export function fetchList(params) {
    return request({
        url: '/post/list',
        method: 'get',
        params: params
    })
}

export function fetchFocus() {
    return request({
        url: '/focus/list',
        method: 'get',
        params: {}
    })
}

export function fetchCategory() {
    return request({
        url: '/category',
        method: 'get',
        params: {}
    })
}

export function fetchFriend() {
    return request({
        url: '/friend',
        method: 'get',
        params: {}
    })
}

export function fetchSocial() {
    return request({
        url: '/social',
        method: 'get',
        params: {}
    });
}

export function fetchSiteInfo() {
    return request({
        url: '/site',
        method: 'get',
        params: {}
    })
}

export function fetchAllQuestion(page) {
    return request({
        url:'/question',
        method:'get',
        params:{current:page.current,size:page.size}
    })
}

//请求发布评论的接口
export function publishComment(Comment) {
    return request({
        url:'/comment/doComment',
        method:'post',
        data:Comment,
        params:{}
    })
}
//点赞信息
export function like(likeInfo) {
    return request({
        url:'/comment/like',
        method:'post',
        data:likeInfo,
        params:{}
    })
}
//取消点赞
export  function dislike(likeInfo) {
    return request({
        url:'/comment/dislike',
        method:'post',
        data:likeInfo,
        params:{}
    })
}
//请求该回答下的所有评论,qid 文章ID
export function getComments(qid) {
    return request({
        url:'/comment/getByAid',
        method:'get',
        params:{"aid":qid}
    })
}
//根据问题的ID获取文章详情
export function getQuestionByID(id) {
    return request({
        url:'/question/getByID',
        method:'get',
        params:{'aid':id}
    })
}
//获取用户信息，根据用户ID
export function getUserByID(id) {
    return request({
        url:'/user/getByUid',
        method:'get',
        params:{'uid':id}
    })
}
//得到所有可以选择的标签

export function fetchAllTags() {
    return request({
        url:'/tag',
        method:'get',
        params:{}
    })
}
//发布问题
export function publishQuestion(question) {
    return request({
        url:'/question',
        method:'post',
        data:question,
        params:{}
    })
}

//插入文字与标签的信息
export function linkTagAndQuestion(tagList,aid) {
    return request({
        url:'/tagArticleLink/linkTag',
        method:'post',
        data:tagList,
        params:{'aid':aid}
    })
}
//更新和问题关联的标签
export function updateLinkedTag(tagList,aid) {
    return request({
        url:'/tagArticleLink/linkTag',
        method:'put',
        data:tagList,
        params:{'aid':aid}
    })
}


//注册
export function register(user) {
    return request({
        url:'/user',
        method:'post',
        data:user,
        params:{}
    })
}
//模糊搜索
export function search(title) {
    return request({
        url:'/question/selectWithTitle',
        method:'get',
        params:{"title":title}
    })
}
//拿到用户关注的问题
export function getForkdQuestion(uid) {
    return request({
        url:'/question/getfocusQuestion',
        method:'get',
        params:{"uid":uid}
    })
}
//关注问题
export function forkQuestion(uid,aid) {
    return request({
        url:'/question/spotQuestion',
        method:'post',
        params:{"uid":uid,"aid":aid}
    })
}

export function fetchComment() {
    return request({
        url: '/comment',
        method: 'get',
        params: {}
    })
}

//登录操作
export function postLogin(account,password,code) {
    return request({
        url: '/login',
        method: 'post',
        params:{
            // 具体传参（键）要看后台要求
            username:account,
            password:password,
            code:code
        }
    })
}
//获取所有标签,带有问题数目
export function getTagsWithNUm(){
    return request({
        url: 'tag/tagWithNum',
        method: 'get',
        params: {}
    })
}
//拿到用户的好友列表
export function getFriends(id) {
    return request({
        url: 'friend/listFriend',
        method: 'get',
        params: {'uid':id}
    })
}
//添加好友的操作
export function addfriend(friend) {
    return request({
        url: 'friend/addfriend',
        method: 'post',
        data:friend,
        params: {}
    })
}
//更新评论操作
export function updateCommet(comment) {
    return request({
        url: 'comment',
        method: 'put',
        data:comment,
        params: {}
    })
}
//获取当前用户的提问
export function getcurUserQuestion(uid ,page){
    return request({
    url: 'question/getQuestionByUid',
    method: 'get',
    params: {'uid':uid,'page':page}
})
}
//用户更新问题
export function updateQuestion(question) {
    return request({
        url:'question',
        method:'put',
        data:question
    })

}
//点赞问题
export function likeQuestion(qid) {
    return request({
        url:'question/like',
        method:'post',
        params:{'qid':qid}
    })
}

export function getTimeLine() {
    return request({
        url: 'timeline',
        method: 'get',
        params: {}
    })
}


